<?php


namespace app\adminapi\dao\member;


use app\common\dao\BaseHotelDao;
use app\common\model\member\MemberLevel;

/**
 * @projectName src
 */
class MemberLevelDao extends BaseHotelDao
{
    public static function add(array $params)
    {
        MemberLevel::create([
            'level_name' => $params['level_name'],
            'total_consume_money' => $params['total_consume_money'],
            'total_consume_time' => $params['total_consume_time']
        ]);
    }

    public static function edit(array $params): bool
    {
        try {
            MemberLevel::update([
                'id' => $params['id'],
                'level_name' => $params['level_name'],
                'total_consume_money' => $params['total_consume_money'],
                'total_consume_time' => $params['total_consume_time']
            ]);
            return true;
        } catch (\Exception $e) {
            self::setError($e->getMessage());
            return false;
        }
    }

    public static function delete(array $params)
    {
        MemberLevel::destroy($params['id']);
    }

    public static function detail(array $params): array
    {
        return MemberLevel::findOrEmpty($params['id'])->toArray();
    }

    public static function getAllData()
    {
        return MemberLevel::order('id', 'desc')->select()->toArray();
    }
}